home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / usr / lib / mozilla-firefox / include / layout / nsHTMLReflowState.h < prev    next >
C/C++ Source or Header  |  2006-05-08  |  21KB  |  494 lines

  1. /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* ***** BEGIN LICENSE BLOCK *****
  3.  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  4.  *
  5.  * The contents of this file are subject to the Mozilla Public License Version
  6.  * 1.1 (the "License"); you may not use this file except in compliance with
  7.  * the License. You may obtain a copy of the License at
  8.  * http://www.mozilla.org/MPL/
  9.  *
  10.  * Software distributed under the License is distributed on an "AS IS" basis,
  11.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  12.  * for the specific language governing rights and limitations under the
  13.  * License.
  14.  *
  15.  * The Original Code is mozilla.org code.
  16.  *
  17.  * The Initial Developer of the Original Code is
  18.  * Netscape Communications Corporation.
  19.  * Portions created by the Initial Developer are Copyright (C) 1998
  20.  * the Initial Developer. All Rights Reserved.
  21.  *
  22.  * Contributor(s):
  23.  *
  24.  * Alternatively, the contents of this file may be used under the terms of
  25.  * either of the GNU General Public License Version 2 or later (the "GPL"),
  26.  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  27.  * in which case the provisions of the GPL or the LGPL are applicable instead
  28.  * of those above. If you wish to allow use of your version of this file only
  29.  * under the terms of either the GPL or the LGPL, and not to allow others to
  30.  * use your version of this file under the terms of the MPL, indicate your
  31.  * decision by deleting the provisions above and replace them with the notice
  32.  * and other provisions required by the GPL or the LGPL. If you do not delete
  33.  * the provisions above, a recipient may use your version of this file under
  34.  * the terms of any one of the MPL, the GPL or the LGPL.
  35.  *
  36.  * ***** END LICENSE BLOCK ***** */
  37. #ifndef nsHTMLReflowState_h___
  38. #define nsHTMLReflowState_h___
  39.  
  40. #include "nsMargin.h"
  41. #include "nsStyleCoord.h"
  42.  
  43. class nsIFrame;
  44. class nsPresContext;
  45. class nsReflowPath;
  46. class nsIRenderingContext;
  47. class nsSpaceManager;
  48. class nsLineLayout;
  49. class nsIPercentHeightObserver;
  50.  
  51. struct nsStyleDisplay;
  52. struct nsStyleVisibility;
  53. struct nsStylePosition;
  54. struct nsStyleBorder;
  55. struct nsStyleMargin;
  56. struct nsStylePadding;
  57. struct nsStyleText;
  58. struct nsHypotheticalBox;
  59.  
  60. /**
  61.  * Constant used to indicate an unconstrained size.
  62.  *
  63.  * @see #Reflow()
  64.  */
  65. #define NS_UNCONSTRAINEDSIZE NS_MAXSIZE
  66.  
  67. /**
  68.  * The reason the frame is being reflowed.
  69.  *
  70.  * XXX Should probably be a #define so it can be extended for specialized
  71.  * reflow interfaces...
  72.  *
  73.  * @see nsHTMLReflowState
  74.  */
  75. enum nsReflowReason {
  76.   eReflowReason_Initial = 0,       // initial reflow of a newly created frame
  77.   eReflowReason_Incremental = 1,   // an incremental change has occured. see the reflow command for details
  78.   eReflowReason_Resize = 2,        // general request to determine a desired size
  79.   eReflowReason_StyleChange = 3,   // request to reflow because of a style change. Note: you must reflow
  80.                                    // all your child frames
  81.   eReflowReason_Dirty = 4          // request to reflow because you and/or your children are dirty
  82. };
  83.  
  84. /**
  85.  * CSS Frame type. Included as part of the reflow state.
  86.  */
  87. typedef PRUint32  nsCSSFrameType;
  88.  
  89. #define NS_CSS_FRAME_TYPE_UNKNOWN         0
  90. #define NS_CSS_FRAME_TYPE_INLINE          1
  91. #define NS_CSS_FRAME_TYPE_BLOCK           2  /* block-level in normal flow */
  92. #define NS_CSS_FRAME_TYPE_FLOATING        3
  93. #define NS_CSS_FRAME_TYPE_ABSOLUTE        4
  94. #define NS_CSS_FRAME_TYPE_INTERNAL_TABLE  5  /* row group frame, row frame, cell frame, ... */
  95.  
  96. /**
  97.  * Bit-flag that indicates whether the element is replaced. Applies to inline,
  98.  * block-level, floating, and absolutely positioned elements
  99.  */
  100. #define NS_CSS_FRAME_TYPE_REPLACED        0x8000
  101.  
  102. /**
  103.  * Helper macros for telling whether items are replaced
  104.  */
  105. #define NS_FRAME_IS_REPLACED(_ft) \
  106.   (NS_CSS_FRAME_TYPE_REPLACED == ((_ft) & NS_CSS_FRAME_TYPE_REPLACED))
  107.  
  108. #define NS_FRAME_REPLACED(_ft) \
  109.   (NS_CSS_FRAME_TYPE_REPLACED | (_ft))
  110.  
  111. /**
  112.  * A macro to extract the type. Masks off the 'replaced' bit-flag
  113.  */
  114. #define NS_FRAME_GET_TYPE(_ft) \
  115.   ((_ft) & ~NS_CSS_FRAME_TYPE_REPLACED)
  116.  
  117. #define NS_INTRINSICSIZE    NS_UNCONSTRAINEDSIZE
  118. #define NS_SHRINKWRAPWIDTH  NS_UNCONSTRAINEDSIZE
  119. #define NS_AUTOHEIGHT       NS_UNCONSTRAINEDSIZE
  120. #define NS_AUTOMARGIN       NS_UNCONSTRAINEDSIZE
  121. #define NS_AUTOOFFSET       NS_UNCONSTRAINEDSIZE
  122. // NOTE: there are assumptions all over that these have the same value, namely NS_UNCONSTRAINEDSIZE
  123. //       if any are changed to be a value other than NS_UNCONSTRAINEDSIZE
  124. //       at least update AdjustComputedHeight/Width and test ad nauseum
  125.  
  126. /**
  127.  * Reflow state passed to a frame during reflow.
  128.  *
  129.  * @see nsIFrame#Reflow()
  130.  */
  131. struct nsHTMLReflowState {
  132.   // the reflow states are linked together. this is the pointer to the
  133.   // parent's reflow state
  134.   const nsHTMLReflowState* parentReflowState;
  135.  
  136.   // the frame being reflowed
  137.   nsIFrame*           frame;
  138.  
  139.   // the reason for the reflow
  140.   nsReflowReason      reason;
  141.  
  142.   // the incremental reflow path, when the reflow reason is
  143.   // eReflowReason_Incremental. Specifically, this corresponds to the
  144.   // portion of the incremental reflow path from `frame' down. Note
  145.   // that it is safe to assume that this is non-null: we maintain the
  146.   // invariant that it contains a valid nsReflowPath pointer when
  147.   // reason == eReflowReason_Incremental.
  148.   nsReflowPath        *path;
  149.  
  150.   // the available width in which to reflow the frame. The space
  151.   // represents the amount of room for the frame's border, padding,
  152.   // and content area (not the margin area. The parent frame deals
  153.   // with the child frame's margins). The frame size you choose should
  154.   // fit within the available width.
  155.   nscoord              availableWidth;
  156.  
  157.   // A value of NS_UNCONSTRAINEDSIZE for the available height means
  158.   // you can choose whatever size you want. In galley mode the
  159.   // available height is always NS_UNCONSTRAINEDSIZE, and only page
  160.   // mode involves a constrained height. The element's the top border
  161.   // and padding, and content, must fit. If the element is complete
  162.   // after reflow then its bottom border, padding and margin (and
  163.   // similar for its complete ancestors) will need to fit in this
  164.   // height.
  165.   nscoord              availableHeight;
  166.  
  167.   // rendering context to use for measurement
  168.   nsIRenderingContext* rendContext;
  169.  
  170.   // The type of frame, from css's perspective. This value is
  171.   // initialized by the Init method below.
  172.   nsCSSFrameType   mFrameType;
  173.  
  174.   // pointer to the space manager associated with this area
  175.   nsSpaceManager* mSpaceManager;
  176.  
  177.   // LineLayout object (only for inline reflow; set to NULL otherwise)
  178.   nsLineLayout*    mLineLayout;
  179.  
  180.   // The appropriate reflow state for the containing block (for
  181.   // percentage widths, etc.) of this reflow state's frame.
  182.   const nsHTMLReflowState *mCBReflowState;
  183.  
  184.   // The computed width specifies the frame's content area width, and it does
  185.   // not apply to inline non-replaced elements
  186.   //
  187.   // For replaced inline frames, a value of NS_INTRINSICSIZE means you should
  188.   // use your intrinsic width as the computed width
  189.   //
  190.   // For block-level frames, the computed width is based on the width of the
  191.   // containing block, the margin/border/padding areas, and the min/max width.
  192.   // A value of NS_SHRINKWRAPWIDTH means that you should choose a width based
  193.   // on your content. The width may be as large as the specified maximum width
  194.   // (see mComputedMaxWidth).
  195.   nscoord          mComputedWidth; 
  196.  
  197.   // The computed height specifies the frame's content height, and it does
  198.   // not apply to inline non-replaced elements
  199.   //
  200.   // For replaced inline frames, a value of NS_INTRINSICSIZE means you should
  201.   // use your intrinsic height as the computed height
  202.   //
  203.   // For non-replaced block-level frames in the flow and floated, a value of
  204.   // NS_AUTOHEIGHT means you choose a height to shrink wrap around the normal
  205.   // flow child frames. The height must be within the limit of the min/max
  206.   // height if there is such a limit
  207.   //
  208.   // For replaced block-level frames, a value of NS_INTRINSICSIZE
  209.   // means you use your intrinsic height as the computed height
  210.   nscoord          mComputedHeight;
  211.  
  212.   // Computed margin values
  213.   nsMargin         mComputedMargin;
  214.  
  215.   // Cached copy of the border values
  216.   nsMargin         mComputedBorderPadding;
  217.  
  218.   // Computed padding values
  219.   nsMargin         mComputedPadding;
  220.  
  221.   // Computed values for 'left/top/right/bottom' offsets. Only applies to
  222.   // 'positioned' elements
  223.   nsMargin         mComputedOffsets;
  224.  
  225.   // Computed values for 'min-width/max-width' and 'min-height/max-height'
  226.   nscoord          mComputedMinWidth, mComputedMaxWidth;
  227.   nscoord          mComputedMinHeight, mComputedMaxHeight;
  228.  
  229.   // Compact margin available space
  230.   nscoord          mCompactMarginWidth;
  231.  
  232.   // Cached pointers to the various style structs used during intialization
  233.   const nsStyleDisplay*    mStyleDisplay;
  234.   const nsStyleVisibility* mStyleVisibility;
  235.   const nsStylePosition*   mStylePosition;
  236.   const nsStyleBorder*     mStyleBorder;
  237.   const nsStyleMargin*     mStyleMargin;
  238.   const nsStylePadding*    mStylePadding;
  239.   const nsStyleText*       mStyleText;
  240.  
  241.   // a frame (e.g. nsTableCellFrame) which may need to generate a special 
  242.   // reflow for percent height calculations 
  243.   nsIPercentHeightObserver* mPercentHeightObserver;
  244.  
  245.   // a frame (e.g. nsTableFrame) which initiates a special reflow for percent height calculations 
  246.   nsIFrame* mPercentHeightReflowInitiator;
  247.  
  248.   // CSS margin collapsing sometimes requires us to reflow
  249.   // optimistically assuming that margins collapse to see if clearance
  250.   // is required. When we discover that clearance is required, we
  251.   // store the frame in which clearance was discovered to the location
  252.   // requested here.
  253.   nsIFrame** mDiscoveredClearance;
  254.  
  255.   // This value keeps track of how deeply nested a given reflow state
  256.   // is from the top of the frame tree.
  257.   PRInt16 mReflowDepth;
  258.  
  259.   struct ReflowStateFlags {
  260.     PRUint16 mSpecialHeightReflow:1; // used by tables to communicate special reflow (in process) to handle
  261.                                      // percent height frames inside cells which may not have computed heights
  262.     PRUint16 mNextInFlowUntouched:1; // nothing in the frame's next-in-flow (or its descendants)
  263.                                      // is changing
  264.     PRUint16 mIsTopOfPage:1;         // is the current context at the top of a page?
  265.     PRUint16 mBlinks:1;              // Keep track of text-decoration: blink
  266.     PRUint16 mVisualBidiFormControl:1; // Keep track of descendants of form controls on Visual Bidi pages
  267.     PRUint16 mHasClearance:1;        // Block has clearance
  268.     PRUint16 mAssumingHScrollbar:1;  // parent frame is an nsIScrollableFrame and it
  269.                                      // is assuming a horizontal scrollbar
  270.     PRUint16 mAssumingVScrollbar:1;  // parent frame is an nsIScrollableFrame and it
  271.                                      // is assuming a vertical scrollbar
  272.   } mFlags;
  273.  
  274. #ifdef IBMBIDI
  275.   nscoord mRightEdge;
  276. #endif
  277.  
  278. #ifdef DEBUG
  279.   // hook for attaching debug info (e.g. tables may attach a timer during reflow)
  280.   void* mDebugHook;
  281.  
  282.   static const char* ReasonToString(nsReflowReason aReason);
  283. #endif
  284.  
  285.   // Note: The copy constructor is written by the compiler automatically. You
  286.   // can use that and then override specific values if you want, or you can
  287.   // call Init as desired...
  288.  
  289.   // Initialize a <b>root</b> reflow state with a rendering context to
  290.   // use for measuring things.
  291.   nsHTMLReflowState(nsPresContext*          aPresContext,
  292.                     nsIFrame*                aFrame,
  293.                     nsReflowReason           aReason,
  294.                     nsIRenderingContext*     aRenderingContext,
  295.                     const nsSize&            aAvailableSpace);
  296.  
  297.   // Initialize a <b>root</b> reflow state for an <b>incremental</b>
  298.   // reflow.
  299.   nsHTMLReflowState(nsPresContext*          aPresContext,
  300.                     nsIFrame*                aFrame,
  301.                     nsReflowPath*            aReflowPath,
  302.                     nsIRenderingContext*     aRenderingContext,
  303.                     const nsSize&            aAvailableSpace);
  304.  
  305.   // Initialize a reflow state for a child frames reflow. Some state
  306.   // is copied from the parent reflow state; the remaining state is
  307.   // computed. 
  308.   nsHTMLReflowState(nsPresContext*          aPresContext,
  309.                     const nsHTMLReflowState& aParentReflowState,
  310.                     nsIFrame*                aFrame,
  311.                     const nsSize&            aAvailableSpace,
  312.                     nsReflowReason           aReason, 
  313.                     PRBool                   aInit = PR_TRUE);
  314.  
  315.   // Same as the previous except that the reason is taken from the
  316.   // parent's reflow state.
  317.   nsHTMLReflowState(nsPresContext*          aPresContext,
  318.                     const nsHTMLReflowState& aParentReflowState,
  319.                     nsIFrame*                aFrame,
  320.                     const nsSize&            aAvailableSpace);
  321.  
  322.   // Used when you want to override the default containing block
  323.   // width and height. Used by absolute positioning code
  324.   nsHTMLReflowState(nsPresContext*          aPresContext,
  325.                     const nsHTMLReflowState& aParentReflowState,
  326.                     nsIFrame*                aFrame,
  327.                     const nsSize&            aAvailableSpace,
  328.                     nscoord                  aContainingBlockWidth,
  329.                     nscoord                  aContainingBlockHeight,
  330.                     nsReflowReason           aReason);
  331.  
  332.   // This method initializes various data members. It is automatically
  333.   // called by the various constructors
  334.   void Init(nsPresContext* aPresContext,
  335.             nscoord         aContainingBlockWidth = -1,
  336.             nscoord         aContainingBlockHeight = -1,
  337.             nsMargin*       aBorder = nsnull,
  338.             nsMargin*       aPadding = nsnull);
  339.   /**
  340.    * Find the content width of the containing block of aReflowState
  341.    */
  342.   static nscoord
  343.     GetContainingBlockContentWidth(const nsHTMLReflowState* aReflowState);
  344.  
  345.   /**
  346.    * Adjust content MEW take into account the settings of the CSS
  347.    * 'width', 'min-width' and 'max-width' properties.
  348.    */
  349.   nscoord AdjustIntrinsicMinContentWidthForStyle(nscoord aWidth) const;
  350.   /**
  351.    * Adjust content maximum-width take into account the settings of
  352.    * the CSS 'width', 'min-width' and 'max-width' properties.
  353.    */
  354.   nscoord AdjustIntrinsicContentWidthForStyle(nscoord aWidth) const;
  355.  
  356.   /**
  357.    * Find the containing block of aFrame.  This may return null if
  358.    * there isn't one (but that should really only happen for root
  359.    * frames).
  360.    */
  361.   static nsIFrame* GetContainingBlockFor(const nsIFrame* aFrame);
  362.  
  363.   /**
  364.    * Get the page box reflow state, starting from a frames
  365.    * <B>parent</B> reflow state (the parent reflow state may or may not end
  366.    * up being the containing block reflow state)
  367.    */
  368.   static const nsHTMLReflowState*
  369.     GetPageBoxReflowState(const nsHTMLReflowState* aParentRS);
  370.  
  371.   /**
  372.    * Compute the border plus padding for <TT>aFrame</TT>. If a
  373.    * percentage needs to be computed it will be computed by finding
  374.    * the containing block, use GetContainingBlockReflowState.
  375.    * aParentReflowState is aFrame's
  376.    * parent's reflow state. The resulting computed border plus padding
  377.    * is returned in aResult.
  378.    */
  379.   static void ComputeBorderPaddingFor(nsIFrame* aFrame,
  380.                                       const nsHTMLReflowState* aParentRS,
  381.                                       nsMargin& aResult);
  382.  
  383.   /**
  384.    * Calculate the raw line-height property for the given frame. The return
  385.    * value, if line-height was applied and is valid will be >= 0. Otherwise,
  386.    * the return value will be <0 which is illegal (CSS2 spec: section 10.8.1).
  387.    */
  388.   static nscoord CalcLineHeight(nsPresContext* aPresContext,
  389.                                 nsIRenderingContext* aRenderingContext,
  390.                                 nsIFrame* aFrame);
  391.  
  392.   void InitFrameType();
  393.  
  394.   void ComputeContainingBlockRectangle(nsPresContext*          aPresContext,
  395.                                        const nsHTMLReflowState* aContainingBlockRS,
  396.                                        nscoord&                 aContainingBlockWidth,
  397.                                        nscoord&                 aContainingBlockHeight);
  398.  
  399.   void CalculateBlockSideMargins(nscoord aAvailWidth,
  400.                                  nscoord aComputedWidth);
  401.  
  402.   /**
  403.    * Apply the mComputed(Min/Max)(Width/Height) values to the content
  404.    * size computed so far. If a passed-in pointer is null, we skip
  405.    * adjusting that dimension.
  406.    */
  407.   void ApplyMinMaxConstraints(nscoord* aContentWidth, nscoord* aContentHeight) const;
  408.  
  409. protected:
  410.  
  411.   void InitCBReflowState();
  412.  
  413.   void InitConstraints(nsPresContext* aPresContext,
  414.                        nscoord         aContainingBlockWidth,
  415.                        nscoord         aContainingBlockHeight,
  416.                        nsMargin*       aBorder,
  417.                        nsMargin*       aPadding);
  418.  
  419.   void CalculateHypotheticalBox(nsPresContext*    aPresContext,
  420.                                 nsIFrame*          aPlaceholderFrame,
  421.                                 nsIFrame*          aBlockFrame,
  422.                                 nsMargin&          aBlockContentArea,
  423.                                 const nsHTMLReflowState* cbrs,
  424.                                 nsHypotheticalBox& aHypotheticalBox);
  425.  
  426.   void InitAbsoluteConstraints(nsPresContext* aPresContext,
  427.                                const nsHTMLReflowState* cbrs,
  428.                                nscoord aContainingBlockWidth,
  429.                                nscoord aContainingBlockHeight);
  430.  
  431.   void ComputeRelativeOffsets(const nsHTMLReflowState* cbrs,
  432.                               nscoord aContainingBlockWidth,
  433.                               nscoord aContainingBlockHeight);
  434.  
  435.   void ComputeBlockBoxData(nsPresContext* aPresContext,
  436.                            const nsHTMLReflowState* cbrs,
  437.                            nsStyleUnit aWidthUnit,
  438.                            nsStyleUnit aHeightUnit,
  439.                            nscoord aContainingBlockWidth,
  440.                            nscoord aContainingBlockHeight);
  441.  
  442.   void ComputeHorizontalValue(nscoord aContainingBlockWidth,
  443.                                      nsStyleUnit aUnit,
  444.                                      const nsStyleCoord& aCoord,
  445.                                      nscoord& aResult);
  446.  
  447.   void ComputeVerticalValue(nscoord aContainingBlockHeight,
  448.                                    nsStyleUnit aUnit,
  449.                                    const nsStyleCoord& aCoord,
  450.                                    nscoord& aResult);
  451.  
  452.   // Computes margin values from the specified margin style information, and
  453.   // fills in the mComputedMargin member
  454.   void ComputeMargin(nscoord aContainingBlockWidth,
  455.                      const nsHTMLReflowState* aContainingBlockRS);
  456.   
  457.   // Computes padding values from the specified padding style information, and
  458.   // fills in the mComputedPadding member
  459.   void ComputePadding(nscoord aContainingBlockWidth,
  460.                       const nsHTMLReflowState* aContainingBlockRS);
  461.  
  462.   // Calculates the computed values for the 'min-Width', 'max-Width',
  463.   // 'min-Height', and 'max-Height' properties, and stores them in the assorted
  464.   // data members
  465.   void ComputeMinMaxValues(nscoord                  aContainingBlockWidth,
  466.                            nscoord                  aContainingBlockHeight,
  467.                            const nsHTMLReflowState* aContainingBlockRS);
  468.  
  469.   nscoord CalculateHorizBorderPaddingMargin(nscoord aContainingBlockWidth);
  470.  
  471.   // Adjust Computed sizes for Min/Max Width and box-Sizing (if
  472.   // aAdjustForBoxSizing is true)  
  473.   // - guarantees that the computed height/width will be non-negative
  474.   //   If the value goes negative (because the padding or border is greater than
  475.   //   the width/height and it is removed due to box sizing) then it is driven to 0
  476.   void AdjustComputedHeight(PRBool aAdjustForBoxSizing);
  477.   void AdjustComputedWidth(PRBool aAdjustForBoxSizing);
  478.  
  479. #ifdef IBMBIDI
  480.   /**
  481.    * Test whether the frame is a form control in a visual Bidi page.
  482.    * This is necessary for backwards-compatibility, because most visual
  483.    * pages use logical order for form controls so that they will
  484.    * display correctly on native widgets in OSs with Bidi support
  485.    * @param aPresContext the pres context
  486.    * @return whether the frame is a BIDI form control
  487.    */
  488.   PRBool IsBidiFormControl(nsPresContext* aPresContext);
  489. #endif
  490. };
  491.  
  492. #endif /* nsHTMLReflowState_h___ */
  493.  
  494.